home *** CD-ROM | disk | FTP | other *** search
/ El Mac 8 / El Mac 8.iso / Shareware / Applications / 4th Artificial Life / Life.4th < prev    next >
Encoding:
Text File  |  1996-03-15  |  1.6 KB  |  39 lines  |  [TEXT/MSWD]

  1. \ ****** LIFE  in  FORTH  by  MERVYN@xs4all.nl *******
  2. --> Extended.4th
  3. variable FIELD 2600 allot  variable FIELD2 2600 allot  
  4. variable PLACE variable PL variable X variable Y  create "TITLE" ," Life"  
  5. : COPYFIELDS  2600 0 Do  I FIELD2 + @  I FIELD + !  2 +Loop ;
  6. : SETUP Begin  2480 80 Do  80 0 Do   
  7.     I J + FIELD2 + @  1 = if I 5 * J 80 - 6 / !PEN ." *" then 
  8.     2 +Loop  80 +Loop  key 
  9.     dup 28 = if PLACE @ 2 - PLACE ! then
  10.     dup 29 = if PLACE @ 2 + PLACE ! then
  11.     dup 30 = if PLACE @ 80 - PLACE ! then
  12.     dup 31 = if PLACE @ 80 + PLACE ! then
  13.     dup 32 = if  1 FIELD2 PLACE @ + !  then
  14.            13 = Until ;
  15. : INIT  FIELD2 2600 0 fill  COPYFIELDS 1400 PLACE !  
  16.     BLACK bcolor WHITE fcolor 500 310 wsize  "TITLE" wtitle page 
  17.     CR CR 
  18.     ."       LIFE by Mervyn@xs4all.nl (programmed in Forth)" CR CR
  19.     ."       LIFE calculates new board populations using these rules:" CR
  20.     ."       -3 neighbours? -> Birth " CR
  21.     ."       -Less than 2 or more than 3 neighbours? -> Death" CR CR
  22.     ."       Press any key to toggle between <Field setup> and <Life>" CR
  23.     ."       (Use space/arrow keys to create a field)  " 
  24.     key drop page SETUP ; 
  25. : MAINLOOP  2480 80 Do  80 0 Do  I J + FIELD + PL !    
  26.     PL @ 2 + @         PL @ 2 - @    
  27.     PL @ 78 + @        PL @ 78 - @ 
  28.     PL @ 80 + @        PL @ 80 - @     
  29.     PL @ 82 + @        PL @ 82 - @    
  30.     + + + + + + +  PL @ @ 
  31.     0 = if 3 = if 1 I J + FIELD2 + !  I 5 * J 80 - 6 / !PEN ." *" then else
  32.     dup 2 < if 0 I J + FIELD2 + ! I 5 * J 80 - 6 / !PEN ."  " drop else 
  33.            3 > if 0 I J + FIELD2 + ! I 5 * J 80 - 6 / !PEN ."  " then then then
  34.     2 +Loop  80 +Loop ?TERMINAL if SETUP then ;
  35. : LIFE INIT Begin  COPYFIELDS  MAINLOOP Again ; 
  36. READY                            \ "echo on"
  37. LIFE                             \ "types LIFE to run itself"
  38.  
  39.